#pragma once

#include "stdafx.h"
#include "ZGameMessageHandler.h"
#include "ZStream.h"
#include <assert.h>

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
bool GameMessageHandler::handle(Stream& stream, NetworkId kNetworkId)
{
	GameMessageId id;
	stream.peek(&id, sizeof(id));
	GameMessageCommandPtrs::iterator i = mCommands.find(id);
	if(i == mCommands.end())
		return false;
	stream.pop(sizeof(id));
	i->second->execute(stream, kNetworkId);
	return true;
}

void GameMessageHandler::addCommand(GameMessageCommandPtr kCommandPtr)
{
	bool kResult	= mCommands.insert(GameMessageCommandPtrs::value_type(kCommandPtr->getGameMessageId(), kCommandPtr)).second;
	assert(kResult);
}

}